This looks pretty generic, it could probably be moved out into a utility module