Changed placement of hook to be able to access variables better