Fixed problem caused by moving routine
Some code clean up.