Some tweaking and bug fixing