fixing bugs, refactoring.