Added and fixed method declarations
Refactores pendingWrites to a map, removed unused structs

and added some return values to functions
Fixed type missmatch,
generalized a loop