Reorganized files and added error catching