Refactor some code to a seperate function
Fix android code