changed tick function to use reduce