Removed a lot of ugly code and made it nice