Added error exception handling