refactored. thanks faizaan