changed file structure and implemented error handling