helper function to serialize lua tables
minor refactorings