changed input structure, consolidated code across files