avoid multiple printf calls & cleanup code