Improved enqueue function