Buncha bug fixes