Fixed some logic errors and finalised class