cleaned up and streamlined some code