Code quality improvements, thanks to @Bakual and @beat