did a bit of refactoring and polishing