Various functions tweeked and misc cleanup.