Cleaned up bugs identified by Jason Mathews