Work in progress of a more efficient code