Reorganize and encapsulate into classes a bit more