More error checks and fixes