refactored to use lua tables