thread-safe and ugly!