applying function unser proper conditions