Modified acoording to Dan's instruction.