Cleaned up code and simplified function calls.