Added length check, human readable error and extra tests