Refactor DecodeWays and clean to make it more clear