added pdb writing and several updates