Added more checks to window initialisation code.
Added const-function correctness.