Based on original commit made by Seon Rozenblum aka @UnexpectedMaker. Signed-off-by: Damien George <damien@micropython.org>