Bug Fixes and error checking