Small bugfix, some refacting needed