Remove unused code and updated math