Working code

Will make some changes later on