code cleanup. hopefully reduced memory usage