Internalise Window and cleanup code
Fixed window bug
Code cleanup