fixed casting issue  and started perf improvements
major perf improvements