revision 5: works for 1 and 2