Added unit tests with related enhancements and fixes