Refactored some stuff to ease implementation of new code ideas.