Restructure and some changes to make the code easier to read and to run both on localhost and on DartVoid.