Fix crash on Froyo due to missing method and refactor some code