add error checking and clearer message order