First really working version, fixed logging