Refactored the layered structure and added initial lua scripting