Added new constructor and cleaned up the code