Cleaned and refactored utility code to make usage much simpler