sizeable refactor + ad hoc testing a bugfixing.