Refactor for a more functional style and no android dependencies.