optimization + other fixes