clean up and economized some code