added helper functions for max and min

also included write file