remove unused function
more improvements, cleanup and commenting