adding unit tests
efficiency improvements