added optimized min/max, gave credit to bithacks