Write more function, make function more flexible