Got off my lazy ass and wrote the function