Added tests, refactoring updates