Refactorings, and fixed bugs