More generic code
Adding support for memory usage