Moved some utility functions to Swift