Draft version of solution. Still need to add more test cases