major refactor. many additions