Fixed some bugs discovered by PMD