modulariing the code and taking care of warnings