title added and better structure of code than previous version