Cleanup and added a few utility functions.