Bug fixing, code refactoring