various fixes

using enumerate instead of counters
using a buffer instead of looping string instantiation