lots of refactoring
fixed syntax error in testing code