fixed a few bugs
merged with master