Refractored functions.php a lot and added some documentation.