bugfixes
added checks to avoid some warnings