implemented proper Exception handling