made changes to have top attributes output in same order as the templates were given. Also now moved the logic for choosing top attributes to the write function