add logging and clean up