proper error checking added