added syntax checks
use printf for complex formatted strings, reformatted using rbeautify