First pass at the implementation of the new algorithm