cleaning up code and attempting to fix null pointer in gui