small tweaks and clean up the up the code