fixed null-pointer exception
fixed some uninitialised memory related bugs
added init method to fix uninitialsed memory bugs