code cleanup and a first try at jasmine tests