overhauling programme to use structs, increase readability