cleaned up code and made some tweaks and comments -KL