modified the code from feedback on 23/8/13