fixed deprecated function hooks, made functions more robust, cleand up head