Fixed bugs in initialization