Cleaned up duplicate function