rewrote function - seems like things work