add hooks and clean up