cleaned up $nin code