changed algorithm to use theta