cleaned up code
make changes according to your comments