Various bug fixes =(