enhancement and fixing some function