Code clean up, better exception handling in Shell