expanded + reformatted code that was difficult to read, see #88