Added proper exception handlings