cache parameter to save some cpu cycles
Replace select(){..}.first with detect() to save some cpu cycles
Fix code style issues