made exception handling better