Fixed bugs
Need refactoring