Added logging and too much other stuff... q_q