Changed the approach using hashes and other methods