cleaned up and simplified the implementation; added a simple test script