Removed magic numbers, and more

Also changed of often the algorithm is called on