Made the code bit more efficient