Working code

Checked on analyser and made prettier