adding assertions and some clean up