cleaned up completion function