Error checking and some other small stuff