WEBCMS-24 - Refactor, start unit tests, minor bug fixes

Refactor, start unit tests, minor bug fixes