cleaned up code and fixed ceiling bug