Bug fix, separating functions out