Fixed some refractoring issues, simplified some code.