code cleanup, documentation and some ui sugar