streamlined functions 
  - moved debug code to seperate functions and commented out