Added error check
Passed to PSR and added error passing