Move window code to class