hack a well working compromise between memory usage and complexity