updated code with my own functions