cleanup and code improvements