made scaning one loop instead of two