Fixed bugs and added gravity compensation for activity.