code clean up + tests