added more unit tests, modified functions where unit testing identified improvements