Changed the return type of some function calls and some error checking