Revised and optimised the entire source code for improved readability and memory usage.