fixed the problem from last commit, simulation shows incorrect results, will work on it next time