Force buffer to be terminated
Fix typo
Free variables on exit
Check for !cs before expanding variables