refactors code for compliance with spec