Lots of cleanup; adding hooks