Cleanup and Comment

Cleanup functions and write comments.