Use t.step_func to simplify code

As per: https://critic.hoppipolla.co.uk/showcomment?chain=4438
Format loop

As per: https://critic.hoppipolla.co.uk/showcomment?chain=4439