create common functions. refactor ctrls