bugs fixed

Javadoc is not ok, but everything else seems to be ok at the moment.