Remove some redundant code and move it to user_d.c so its in just one place.
Also did some small formating changes to the effected files.
merge pull from sirdude
update the auto function kfun impl