compacted acc function, got to test this