Commit 2

Clean, debug, adapt and add elements to the function