Enhanced refactoring and added unit tests following up to commit 6e6af8f