modularized some of the code better
put in expected percent error code