More error checks. Full implementation of the spec