Tweaking and fixing code