more functions and error checking