Cleaned up algorithm. Imported future division