converted more code to functional style