The solution is here! Some weird bugs left though.