STAN - code refactored to meet 30 lines limit