Refactored template, added unit tests