bit of refactoring but crashed under android :(