Remove unneeded routines, move code and minor style fix.