added a bunch of initial code
first pass at cleanup