Replaced some code with a simpler version