Bugs and errors fixed