some error checking added