Updated code and reworked exception catching