refactored a little bit..