Reworked so its faster and correct