Hash function and other improvements