Finalized first iteration; added more documentation; cleaned up memory management