Added logging, trimmed some stuff