added locking and also now compiled without warnings :)