Changed sprintf to snprintf to suppress compiler warnings