changed some code around to make it run a bit faster