Used ugly code to solve