The code before adding loops and search conditions. 06/04/13