fixed up the preInfinity to take account into cog_ctrl as well as optimized the code for better performance.