added helper method and fixed broken code and comments