Long codes are bad for health, please refactor this for proper review.