added rooting procedure and some code cleanup