some restructuring and fix little issues