Added the start of the logic engine and refactored code a bit