Adding logging support ,and lot of improvements/bugfixes