Fixed prototype methods, added error checking