Major update: organised custom stuff into lib/ folder for easier
management