Added some optimzations