Fix a bit, turn it to functional style