More code refactoring and code testing