Extensively commented everything. Removed a few excessive if statements and reordered a thing or two.