Modifed both functions, they appear to be working