Move functions from window.c