Hopefully added a bit more error checking.