cleanup, improvements and logging