abstracted code a little more, cleanup flow