Added exception handling