Re-organized functions some more