small changes and error checking