Some cleanup/bug fixes