Made the core function way more generic.