quickEncode needs refactoring