moved err check