I've looked into this and changed the function, probably not perfect yet but it was an improvement.