move all the logic here.