Re-factored to a separate class, added unit tests