First implementation direct memory
Working version
After merging