Cleaned up code and commenting