Refactored toString function to get rid of unpleasant overflows