moved everything to function form