Simplified some code, added comments.