Modified logging slightly and made it more flexible