organized the file

put helper functions in beggining
add comment headers