Fixed some bugs in initial commit