dividing the code inside the constructor into methods