Fixed some problems pointed out by kovidgoyal

Ref #335.