fixed some bugs (found with "findbugs")