implemented matheus's bugfixes