break main up in to functions
add better comments