memory: overflow fix and minor changes
Merge pull request #38 from FrodeSolheim/memory

memory: overflow fix and minor changes