Cleaned up code and renamed function and variables