Cleanup, add comments and explanations