more cleanups and refactors
fixed error in last commit