better way to coding this