Clean up sub algorithm code