added more structure to main file and further exception handling