added logging, cleaned up