fixed JPanel and some inefficient code