Minor bug fixes, with same features as previous commit.