Update corefunctions.php

Cleaning a lot of it up.... New code. || Not tested ||