Fixed bug and some errors