cleaned up code and made it better