Windows compatibility

Added Windows compatibility
Fixed locking
Moved user variables to top
Merge pull request #1 from kamikadzew/patch-1

Windows compatibility