reorganized includes and error handling