functioning ugly code