Moved out some util functions to make it a little cleaner