work in progress... (refactor, cleanup)