created functions, fixed code