Clean up code and small fix