refactored a little bit to meet former JAson's comments