Works properly now. Will add timing for good measure