[IMP] Code cleaning plus some misc bug fixes, improvements