cleaned up code + added comments