add specs and a some small refactors