Huge refactor based on heapster