Refactor to use as Android library