Windows Errors. Code improvements