Moved exception handling into approprioate place