Added tolerance support and specification in test definition file. Cleaned up code. Added error checks.