closes ChicagoBoss/ChicagoBoss#323
refactoring and tests