More refactoring, this time using NetBeans' 'inspect' tool to find potential bugs. It's pretty handy.