added test scripts

and refactored code to add debug statements