reworked all files for better error handling and exiting cleanup
fixed sloppy code and optimized performance some
organized code for consistency