Refactored API code so that more of the logic is in java activities and
less is in php.