Better error checking

Better in that it doesn't fail whenever valid input comes through...