bug fixing & refactoring