Tree-based Barnes-Hut algorithm implementation for nbody simulations