Made the code faster by around 20%