Tiny optimization and bugfix