More tweaks and error checking