final beta. Done but can be made more efficient.