Moved function to a more suitable location