Fix problems mentioned by @sensej