Fix a small bug with last version and optimize some calculations a bit.