Added a logging object and moved some stuff around