bug fixing. seems to work