added unit testing framework and some small code improvements