code cleanup and begin support for selection