Fixed error code checking. Closes #5