Corrected missing ends, added coordinates handling