Fixes multiple bugs