cleaned code a bit
fixed logging error