Modified code with some steps towards implementing the SAx algorithm