cleanup code and handle no results