updated the functions, got it working a lot better