changed implementation to work better with validation