Merging devan's code after suggesting improvements.