added an end for end of function. merged function with hook again.