Added error checking for few functions.