Windows compatibility

Added Windows compatibility
Fixed locking
Moved user variables to top