Move threshold calculation to method