made a few changes and clean up code