Minor optimization and code cleaning