f move error check to where the error happens