Fixes multiple bugs
Fixes various bugs