Changed a bit of code to make it simpler.