added better comments
added helper functions