Additional utility functions and fixed some issues.