Refactor string handling in lib