Some small cleanups and minor bug fix