better exception handling, better format of code