Cleaned up engine and terminal code