Minor cleanup

While checking the code to implement #124, I found a few things that could be optimized, namely:
1. A couple of manual array copies
2. Usage of StringBuffer where StringBuilder would suffice, or StringBuilder where String would suffice
3. Redundant casts

While all of this is just polish, I think there's a lot to gain from the first point, fixed in 9580482.