refactor to use structs for weights and grad