fixed some bugs and warnings + reformating