Refactor phase 2, eliminate  except , and moved rest of functions to prototype