Refactored coordinate output function to process samples individually