rework into one lua file with working tests