Added very dirty implemented, but quite efficient implementation, which generates quite optimized tree.