minor bug fixes + code cleaning