Added new rest detection algorithm