Tested and debugged for 1 and 2