small code cleanup, added logging