changed placement of all functions, and updated comments