Reduce code in view script