improved design and minor bugs fixe