Move window function implementation to util.window