Fixed several warnings/bugs