Worked out a few bugs