code fixed after the comments from @ChaosBelcebub