tests passing. some code improvements