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.