Cleaned up code and simplified