some of the code refactored; added tests script