remove dup code a bit
better error message