Clean up, and reoder the code. Add comments.