bugfix: add synchronized block to prevent EmptyStackExceptions