working on performance optimization by moving around code performing unroll and handle discrete variables