Updated implementation as requested