There were some possibilities of NULL pointer dereferencing. Also, changed one small function to inline.