fixes multiple bugs