refactor

added common funcs and fixed mid window