Fixed 64bit warnings and added control over CACHE_LIMIT without branching the code.